/**
 * @author xuyang
 * @time 2023-05-22 14:44 PM
 * @description 定义路由和配置路由相关
 */

import { createRouter, Router, createWebHashHistory, RouteLocationNormalized, NavigationGuardNext } from 'vue-router'
import { useCommonStore } from '../store'

/* 导入业务组件 */
const Login = () => import('../pages/login/login.vue')
const Home = () => import('../pages/home/index.vue')
const Find = ()=>import('../pages/find/index.vue')
const Mine = ()=>import('../pages/mine/index.vue')
const Heart = ()=>import('../pages/heart/index.vue')
const Person=()=>import('../pages/mine/personal.vue')
const Concern=()=>import('../pages/mine/concern.vue')
const Collection=()=>import('../pages/mine/Collection.vue')
const Letter=()=>import('../pages/mine/letter.vue')
const Audio = ()=>import('../pages/heart/Audio.vue')
const Search = ()=>import('../pages/heart/search.vue')

const Classification=()=>import('../pages/find/classification.vue')//发现板块的跳转分类话题
const Gogroadcast=()=>import('../pages/find/goGroadcast.vue')

/* 定义路由 */
const router: Router = createRouter({
    history: createWebHashHistory(),
    routes: [
        // {path: '/', redirect: '/find'},
        // {path: '/', redirect: '/classification'},//发现板块的跳转分类话题
        {path: '/', redirect: '/login'},


        // {path: '/', redirect: '/mine'},
        // {path: '/', redirect: '/heart'},
        {path: '/login', component: Login},
        {path: '/home', component: Home},
        {path: '/find', component: Find},
        {path: '/mine', component: Mine},
        {path: '/heart', component: Heart},
        {path:'/mine/personal',component:Person},
        {path:'/mine/concern',component:Concern},
        {path:'/mine/Collection',component:Collection},
        {path:'/mine/letter',component:Letter},

        {path: '/classification', component: Classification}, //发现板块的跳转分类话题
        {path: '/goGroadcast', component: Gogroadcast},//跳转精选播单详情

        {path: '/heart/audio', component: Audio},
        {path: '/search', component: Search},
    ]
})

/* 不能再这里进行store获取，因为pinia 初始化还没有完成 */
// useCommonStore()

/* 定义拦截器 */
// router.beforeEach(function(to: RouteLocationNormalized, _: any, next: NavigationGuardNext): void {
//     if (to.meta.nologin) {
//         next()
//         return
//     }

//     let token: string = useCommonStore().tokenVal;

//     if (!!token) {
//         next()
//     } else {
//         next('/login')
//     }
// })

/* 路由实例导出 */
export default router